Skip to content

module: run require.resolve through module.registerHooks()#62028

Merged
nodejs-github-bot merged 3 commits intonodejs:mainfrom
joyeecheung:fix-require-resolve
Mar 2, 2026
Merged

module: run require.resolve through module.registerHooks()#62028
nodejs-github-bot merged 3 commits intonodejs:mainfrom
joyeecheung:fix-require-resolve

Conversation

@joyeecheung
Copy link
Member

Previously, require.resolve() called Module._resolveFilename() directly, bypassing any resolve hooks registered via module.registerHooks(). This patch fixes that.

Previously, require.resolve() called Module._resolveFilename() directly,
bypassing any resolve hooks registered via module.registerHooks(). This
patch fixes that.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Feb 27, 2026
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.65%. Comparing base (76ba280) to head (c1a6de3).
⚠️ Report is 27 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62028      +/-   ##
==========================================
- Coverage   89.73%   89.65%   -0.08%     
==========================================
  Files         676      676              
  Lines      206069   206285     +216     
  Branches    39515    39521       +6     
==========================================
+ Hits       184915   184946      +31     
- Misses      13305    13462     +157     
- Partials     7849     7877      +28     
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 98.14% <100.00%> (-0.22%) ⬇️
lib/internal/modules/esm/loader.js 98.77% <100.00%> (+<0.01%) ⬆️
lib/internal/modules/esm/translators.js 97.65% <100.00%> (+0.01%) ⬆️
lib/internal/modules/helpers.js 98.72% <100.00%> (+0.22%) ⬆️

... and 45 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joyeecheung
Copy link
Member Author

joyeecheung commented Mar 1, 2026

It seems require.resolve has some behavior difference from the internal resolution that would break the older tests, I refactored the implementation a bit so that the default step can behave more like what require.resolve expected when it's being used for require.resolve, and added some comments in require.resolve to note the differences.

@mcollina @GeoffreyBooth @marco-ippolito Can you take a look at the last commit? Thanks!

@nodejs-github-bot
Copy link
Collaborator

@joyeecheung joyeecheung added the review wanted PRs that need reviews. label Mar 2, 2026
@joyeecheung
Copy link
Member Author

CI is green. Can you take another look please? @mcollina @GeoffreyBooth @marco-ippolito

@joyeecheung
Copy link
Member Author

On a side note - I've been working on a POC of polyfilling module.register() in the user land using module.registerHooks() https://github.com/joyeecheung/module-register-ponyfill - most applicable Node.js core tests passes, except require.resolve support which needs this fix

@joyeecheung joyeecheung added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Mar 2, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 2, 2026
@nodejs-github-bot nodejs-github-bot merged commit dd400b9 into nodejs:main Mar 2, 2026
70 of 71 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in dd400b9

richardlau pushed a commit that referenced this pull request Mar 2, 2026
Previously, require.resolve() called Module._resolveFilename() directly,
bypassing any resolve hooks registered via module.registerHooks(). This
patch fixes that.

PR-URL: #62028
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. review wanted PRs that need reviews.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants